package cn.kickegg.log.core.storage;

import cn.kickegg.log.core.model.LogEntry;
import cn.kickegg.log.core.spi.LogStorage;
import cn.kickegg.log.core.mapper.LogEntryMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
@ConditionalOnProperty(name = "log.collector.storage.type", havingValue = "mysql")
public class MySQLLogStorage implements LogStorage {
    
    private final LogEntryMapper logEntryMapper;
    
    public MySQLLogStorage(LogEntryMapper logEntryMapper) {
        this.logEntryMapper = logEntryMapper;
    }
    
    @Override
    public void store(LogEntry logEntry) {
        logEntry.setId(UUID.randomUUID().toString());
        logEntryMapper.insert(logEntry);
    }
    
    @Override
    public String getType() {
        return "mysql";
    }
} 